package com.example.androidlearn.uiwidget;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;

import com.example.androidlearn.R;
import com.example.androidlearn.adapter.MyListViewAdapter;
import com.example.androidlearn.entity.Fruit;

import java.util.ArrayList;
import java.util.List;

public class MListView extends AppCompatActivity {
    private List<Fruit> fruitList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);

        initFruits();
        MyListViewAdapter myListViewAdapter = new MyListViewAdapter(MListView.this,R.layout.fruit_item, fruitList);
        ListView listView = (ListView) findViewById(R.id.my_list_view);
        listView.setAdapter(myListViewAdapter);
    }

    private void initFruits() {
        Fruit apple = new Fruit("apple", R.drawable.img_1);
        fruitList.add(apple);

        Fruit banabn = new Fruit("banban", R.drawable.img_2);
        fruitList.add(banabn);

        Fruit orabe = new Fruit("orabe", R.drawable.img_3);
        fruitList.add(orabe);
    }
}